var prex = 0;
const app = getApp()

Page({
  data: {
    list: [{
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜1~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/1.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜2~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/2.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜3~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/3.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜4~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/4.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜5~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/5.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜6~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/6.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜7~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/7.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜8~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/8.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜9~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/9.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜10~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/10.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      },
      {
        tagName: '唯美',
        tagColor: 'blue',
        light: true,
        title: "嗷呜11~",
        name: "LeeYaMaster",
        image: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/11.jpg",
        avatar: "cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/1.jpg",
        time: "哦嗨哟 sama"
      }
    ],
    //解决动画闪烁问题,把数组里的值，都增加一个层级属性，根据层级来显示动画
    img: [
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/1.jpg",zIndex:3},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/2.jpg",zIndex:2},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/3.jpg",zIndex:1},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/4.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/5.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/6.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/7.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/8.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/9.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/10.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/11.jpg",zIndex:0}
    ],
    idx: 0,
    x: 0,
    y: 0,
    hiddenImg: true,
    animation: false,
    likeAnimation: false,
    unlikeAnimation: false,
    collectionAnimation: false,
  },
  moveimg(e) {
    prex = e.detail.x;
  },
  touchendimg(e) {
    console.log(prex)
    if (prex < -180 || prex > 180) {
      this.hidden();
    } else {
      setTimeout(() => {
        this.setData({
          x: 0,
          y: 0
        })
      }, 300)
    }
  },
  onLoad: function () {
    //多加一些数据，实际开发中，可以删。
    let list = [
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/4.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/5.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/6.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/7.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/8.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/9.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/10.jpg",zIndex:0},
      {url:"cloud://could-3gpmtjxfc5eed68f.636f-could-3gpmtjxfc5eed68f-1304798122/小清新图片/11.jpg",zIndex:0}
    ]
    list = [...list,...list,...list,...list,...list,...list,...list,...list,...list,...list,...list];
    let img = this.data.img;
    img = [...img,...list];
    this.setData({
      img
    })
  },
  collection() {
    this.setData({
      collectionAnimation: true
    })
    setTimeout(() => {
      this.hidden();
      this.setData({
        collectionAnimation: false
      })
    }, 1000)

  },
  like() {
    this.setData({
      likeAnimation: true
    })
    setTimeout(() => {
      this.hidden();
      this.setData({
        likeAnimation: false
      })
    }, 1000)

  },
  unlike() {
    this.setData({
      unlikeAnimation: true
    })
    
    setTimeout(() => {
      this.hidden();
      this.setData({
        unlikeAnimation: false
      })
    }, 1000)
  },
  hidden() {
    this.setData({
      hiddenImg: false,
      animation: true
    });
    // let img = this.data.img;
    // let idx = this.data.idx;
    // img[idx] = undefined;
    // img[idx + 1].zIndex = 3;
    // img[idx + 2].zIndex = 2;
    // img[idx + 3].zIndex = 1;
    setTimeout(() => {
      this.setData({
        hiddenImg: true,
        animation: false,
        // img,
        idx: this.data.idx + 1
      })
      // console.log(this.data.img)
      // console.log(this.data.idx)
    }, 1000)
  }
})